package com.jds.test.httpproxy.httpclient;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * Created by sunyuming on 18/10/23.
 */
public class ReqQueue {

    private static BlockingQueue<OriginHttp> arrayBlockingQueue = new LinkedBlockingDeque<OriginHttp>(100);

    public static void main(String[] args) {

    }


    public static void startConsumer() {
        for(int i=0; i<4; ++i) {
            new Thread(new Customer()).start();
        }
    }

    public static void put(OriginHttp originHttp) {
        try {
            arrayBlockingQueue.put(originHttp);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

    private static class Customer implements Runnable {

        @Override
        public void run() {
            try {
                while (true){
                    OriginHttp originHttp = arrayBlockingQueue.take();
                    ProxySender.send(originHttp);
                    Thread.sleep(100);
                }

            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }

}
